import requests
from PySide6.QtWidgets import QWidget, QLabel, QHBoxLayout
from PySide6.QtGui import QPixmap

class WechatInfoWidget(QWidget):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        m_layout = QHBoxLayout(self)
        self.wechat_avatar = QLabel(self)
        self.wechat_avatar.setFixedSize(40, 40)
        self.wechat_avatar.setScaledContents(True)
        m_layout.addWidget(self.wechat_avatar)

        self.wechat_wx_id = QLabel(self)
        self.wechat_phone = QLabel(self)
        m_layout.addWidget(self.wechat_wx_id)
        m_layout.addWidget(self.wechat_phone)
        self.setLayout(m_layout)

    def set_info(self, data):
        r = requests.get(data['avatar_url'])
        pixmap = QPixmap()
        pixmap.loadFromData(r.content)
        self.wechat_avatar.setPixmap(pixmap)
        self.wechat_wx_id.setText('微信号：{}'.format(data['wx_id']))
        self.wechat_phone.setText('手机号：{}'.format(data['mobile']))

